import Vue from 'vue'
import Router from 'vue-router'
import Layout from '@/layout/index.vue'
import park from './modules/park'
import car from './modules/car'
import system from './modules/system'
import poles from './modules/poles'

Vue.use(Router)

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/workbench'
  },

  {
    path: '/workbench',
    component: Layout,
    children: [{
      path: '',
      component: () => import('@/views/workbench/index'),
      meta: { title: '工作台', icon: 'el-icon-data-board' }
    }]
  },
  park,
  car,

  // 新增月卡管理页
  {
    path: '/cardAdd/:id?/:type?',
    component: () => import('@/views/car/card/card-add'),
    meta: { title: '新增月卡' },
    hidden: true
  },
  // 新增企业页面
  {
    path: '/companyAdd/:id?',
    component: () => import('@/views/park/company/add'),
    meta: { title: '添加企业' },
    hidden: true
  },
  {
    path: '/',
    component: () => import('@/views/car/area/index.vue'),
    meta: { title: '物业费管理', icon: 'el-icon-office-building' }
  },
  poles,
  system,

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
